package com.koron.order.defect.controller;


import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.defect.bean.po.DefectStatus;
import com.koron.order.defect.bean.vo.DefectExecuteVO;
import com.koron.order.defect.service.ExecuteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DefectOrderExecuteController
 * @description
 * @Author zhouj
 * @Date 2021/9/6 16:31
 */
@Api(tags = "缺陷工单执行信息")
@RestController
@RequestMapping("/defect/execute/")
public class DefectExecuteController {

    @Autowired
    private ExecuteService executeService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @Autowired
    DefectController defectController;

    @ApiOperation(value = "新增或保存")
    @PostMapping("saveExecuteInfo")
    public Response<String> insertOrUpdate(@RequestBody DefectExecuteVO defectExecuteVO) {
        defectController.verityStatus(defectExecuteVO.getOrderId(), DefectStatus.IN_EXECUTE.getStatus(),DefectStatus.ARCHIVED.getStatus());
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "insertOrUpdate", String.class, defectExecuteVO));
    }

    @ApiOperation(value = "批量新增 ")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(List<DefectExecuteVO> defectExecuteVOList,Boolean isCommit) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "insertBatch", Integer.class, defectExecuteVOList,isCommit));
    }

    @ApiOperation(value = "根据工单执行id删除 ")
    @DeleteMapping("deleteExecuteInfoByExecuteId")
    public Response<Integer> deleteByOrderExecuteId(String orderExecuteId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "deleteByOrderExecuteId", Integer.class, orderExecuteId));
    }

    @ApiOperation(value = "根据工单id删除 ")
    @DeleteMapping("deleteByOrderId")
    public Response<Integer> deleteByOrderId(String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "deleteByOrderId", Integer.class, orderId));
    }

    @ApiOperation(value = "orderExecuteId查询执行信息")
    @GetMapping("queryExecuteInfoByExecuteId")
    public Response<DefectExecuteVO> queryListByOrderExecuteId(String executeId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "queryListByOrderExecuteId", DefectExecuteVO.class, executeId));
    }

    @ApiOperation(value = "orderId查询执行信息列表")
    @GetMapping("queryExecuteInfoByOrderId")
    public Response<List> queryListByOrderId(String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "queryListByOrderId", List.class, orderId));
    }

    @ApiOperation(value = "orderId查询可提交人员列表")
    @GetMapping("querySubmitUserListByOrderId")
    public Response<List> querySubmitUserListByOrderId(String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), executeService, "querySubmitUserListByOrderId", List.class, orderId));
    }

}
